package com.liam.security;

import com.liam.helper.DatabaseHelper;
import org.smart4j.plugin.security.SmartSecurity;

import java.util.Set;

/**
 * Created by liam on 16/10/11.
 */
public class AppSecurity implements SmartSecurity {
    @Override
    public String getPassword(String name) {
        String sql = "select password from t_user where username = ?";
        return DatabaseHelper.query(sql, name);
    }

    @Override
    public Set<String> getRoleNameSet(String username) {
        String sql = "select r.rol_name from user u,user_role ur,role r where u.id=ur.user_id and r.id=ur.role_id and u.username=?";
        return DatabaseHelper.querySet(sql,username);
    }

    @Override
    public Set<String> getPermissionNameSet(String roleName) {
        String sql = "select p.permission_name from role r,role_permission rp,permission p where r.id=rp.role_id and p.id=rp.permission_id and r.role_name=?";

        return DatabaseHelper.querySet(sql,roleName);
    }
}
